package com.cashmanager.client.view;

import com.smartgwt.client.types.TreeModelType;
import com.smartgwt.client.widgets.events.DrawEvent;
import com.smartgwt.client.widgets.events.DrawHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tree.Tree;
import com.smartgwt.client.widgets.tree.TreeGrid;
import com.smartgwt.client.widgets.tree.TreeGridField;
import com.smartgwt.client.widgets.tree.TreeNode;

public class RunAnalysisPage extends HLayout{

	public RunAnalysisPage() {
		setWidth100();
		setHeight100();
		VLayout v1 = new VLayout();
		v1.setHeight100();
		v1.setWidth("25%");
		VLayout v2 = new VLayout();
		v2.setHeight100();
		v2.setWidth("75%");
		addMember(v1);
		addMember(v2);

		TreeGrid treeGrid = new TreeGrid();
		treeGrid.setWidth100();
		treeGrid.setHeight100();

		TreeGridField field = new TreeGridField("Name", "保存的统计分析查询");
		field.setCanSort(false);

		treeGrid.setFields(field);

		final Tree tree = new Tree();
		tree.setModelType(TreeModelType.PARENT);
		tree.setNameProperty("Name");
		tree.setIdField("EmployeeId");
		tree.setParentIdField("ReportsTo");
		tree.setShowRoot(true);

		EmployeeTreeNode root = new EmployeeTreeNode("4", "1", "已保存");

		EmployeeTreeNode node1 = new EmployeeTreeNode("187", "4", "2005到2011年所有报表");
		EmployeeTreeNode node2 = new EmployeeTreeNode("188", "4",
				"2012年第一季度假币统计图表");
		EmployeeTreeNode node3 = new EmployeeTreeNode("189", "4",
				"2012年第二季度所有图表");

		tree.setData(new TreeNode[] { root, node1, node2, node3 });

		treeGrid.addDrawHandler(new DrawHandler() {
			public void onDraw(DrawEvent event) {
				tree.openAll();
			}
		});

		treeGrid.setData(tree);
		v1.addMember(treeGrid);
		
		NewAnalysisPage page = new NewAnalysisPage();
		page.getClr().hide();
		page.getSave().hide();
		v2.addMember(page);
		
	}

}

class EmployeeTreeNode extends TreeNode {

	public EmployeeTreeNode(String employeeId, String reportsTo, String name) {
		setEmployeeId(employeeId);
		setReportsTo(reportsTo);
		setName(name);
	}

	public void setEmployeeId(String value) {
		setAttribute("EmployeeId", value);
	}

	public void setReportsTo(String value) {
		setAttribute("ReportsTo", value);
	}

	public void setName(String name) {
		setAttribute("Name", name);
	}
}
